<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>Customer Edit History List</title>
  </head>
  <body>
    <div id="customerhistorygrid"">
         </div>
    <script>
        /*
         * Ext JS Library 2.2
         * Copyright(c) 2006-2008, Ext JS, LLC.
         * licensing@extjs.com
         *
         * http://extjs.com/license
         */
        //为了一般JS方法可以调用，这个变量定义要放在onReady外面．
        var customerHistoryDS;
        var birthDay;
        Ext.onReady(function(){
            Ext.QuickTips.init();
            Ext.form.Field.prototype.msgTarget = 'side';
            // fix the bug in codepress - resize
            //Ext.BoxComponent.prototype.setSize('100%', '125px');
            /************************************************************
             * Display the result in page
             * the column model has information about grid columns
             * dataIndex maps the column to the specific data field in
             * the data store (created below)
             ************************************************************/
            var customerHistoryCM = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(), {
                    id: 'id',
                    header: "Identify",
                    dataIndex: 'id',
                    width: 25,
                    hidden: true
                }, {
                    header: "客户名称",
                    width: 60,
                    dataIndex: 'name'
                }, {
                    header: "性别",
                    width: 30,
                    dataIndex: 'sex'
                }, {
                    header: "电话",
                    width: 80,
                    dataIndex: 'phone'
                }, {
                    header: "证件类型",
                    width: 60,
                    dataIndex: 'card_type'
                }, {
                    header: "证件号码",
                    width: 80,
                    dataIndex: 'card'
                }, {
                    header: "生日",
                    width: 70,
                    dataIndex: 'birthday',
                    renderer: Ext.util.Format.dateRenderer('Y-m-d')
                }, {
                    header: "会员卡号",
                    width: 80,
                    dataIndex: 'customer_no'
                }, {
                    header: "地址",
                    width: 100,
                    dataIndex: 'address'
                }, {
                    header: "联系人",
                    width: 60,
                    dataIndex: 'linkman'
                }, {
                    header: "联系人电话",
                    width: 90,
                    dataIndex: 'linkman_phone'
                }, {
                    header: "类型",
                    width: 70,
                    dataIndex: 'customer_type'
                }, {
                    header: "修改人",
                    width: 60,
                    dataIndex: 'edit_by'
                }, {
                    header: "修改日期",
                    width: 100,
                    dataIndex: 'created_at',
                    renderer: Ext.util.Format.dateRenderer('Y-m-d H:i:s')
                }]);
            /************************************************************
             * connect to backend - grid - core part
             * create the Data Store
             *   connect with backend and list the result in page
             *   through JSON format
             ************************************************************/
            customerHistoryDS = new Ext.data.Store({
                // load using script tags for cross domain, if the data in on the same domain as
                // this page, an HttpProxy would be better
                proxy: new Ext.data.HttpProxy({
                    url: '/customers/getCustomerHistory?customer_id=' + '<%=@customer_id%>'
                }),
                // create reader that reads the Topic records
                reader: new Ext.data.JsonReader({
                    root: 'root',
                    totalProperty: 'totalProperty',
                    id: 'id'
                }, [{
                        name: 'id'
                    }, {
                        name: 'name'
                    }, {
                        name: 'sex'
                    }, {
                        name: 'phone'
                    }, {
                        name: 'card_type',
                        mapping: 'card_type.card_type'
                    }, {
                        name: 'card'
                    }, {
                        name: 'birthday'
                    }, {
                        name: 'customer_no'
                    }, {
                        name: 'address'
                    }, {
                        name: 'linkman'
                    }, {
                        name: 'linkman_phone'
                    }, {
                        name: 'customer_type',
                        mapping: 'customer_type.customer_type'
                    }, {
                        name: 'edit_by',
                        mapping: 'user.user_name'
                    }, {
                        name: 'created_at'
                    }])
            });
                
                
            /************************************************************
             * define grid panel now
             ************************************************************/
            var customerHistoryGridPanel = new Ext.grid.GridPanel({
                border: false,
                el: 'customerhistorygrid',
                ds: customerHistoryDS,
                cm: customerHistoryCM,
                autoWidth: true,
                viewConfig: {
                    forceFit: true
                },
                loadMask: true,
                iconCls: 'icon-grid',
                collapsible: true,
                animCollapse: false,
                autoWidth: true,
                //frame: true,
                height: 280,
                title: '记录列表'
            });
            //panel render
            customerHistoryGridPanel.render();
            // trigger the data store load
            customerHistoryDS.load();
        });
    </script>
  </body>
</html>
